package com.nsqt.banquan.controller;

import com.nsqt.banquan.domain.WorkDO;
import com.nsqt.banquan.service.WorkService;
import com.nsqt.biz.service.AgentService;
import com.nsqt.common.utils.PageUtils;
import com.nsqt.common.utils.Query;
import com.nsqt.common.utils.ShiroUtils;
import com.nsqt.system.domain.UserDO;
import com.nsqt.system.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 未提交版权
 */
@Controller("unsubmitWorkController")
@RequestMapping("/banquan/unsubmit")
public class UnsubmitSoftwareController {
    @Autowired
    private WorkService workService;
    @Autowired
    private AgentService agentService;
    @Autowired
    private UserService userService;

    @GetMapping()
    @RequiresPermissions("banquan:unsubmit:unsubmit")
    String Unsubmit() {
        return "banquan/unsubmit/unsubmit";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("banquan:unsubmit:unsubmit")
    public PageUtils unsubmitlist(@RequestParam Map<String, Object> params, Model model) {
        Long userId = ShiroUtils.getUserId();
        UserDO user = userService.get(userId);
        List<Long> roles = user.getRoleIds();
        params.put("status", 0);
        //查询列表数据
        Query query = new Query(params);
        if ((!roles.contains(new Long(1))) && (!roles.contains(new Long(2))) && (!roles.contains(new Long(4)))) {
            query.put("businessMan", userId);
        }
        String agentCompany = (String) query.get("agentCompany");
        if (agentCompany == null || agentCompany.equals("")) {

        } else {
            query.put("agentCompany", agentCompany);
        }
        //query.put("sort","status");
        List<WorkDO> softwareList = workService.listUnsubmit(query);

        int total = workService.countUnsubmit(query);
        PageUtils pageUtils = new PageUtils(softwareList, total);

        return pageUtils;
    }


}
